//package fr.mabdylon.gamexperience.core.old;
//
//import com.sun.corba.se.spi.activation.Server;
//import processing.core.PApplet;
//import processing.core.PVector;
////import processing.net.Server;
//import fr.mabdylon.gamexperience.particles.Ball;
//
//public class BigPlanck extends PApplet {
//
//	/**
//	 * 
//	 */
//	private static final long serialVersionUID = 4707419214185535163L;
//	/**
//	 * Circle Collision with Swapping Velocities by Ira Greenberg.
//	 * 
//	 * Based on Keith Peter's Solution in Foundation Actionscript Animation:
//	 * Making Things Move!
//	 */
//
////	public Server myServer;
//	public int val = 0;
//	public Ball[] balls;
//	public PVector[] vels;
//	public int MAX_RANDOM_SIZE = 50;
//	public int MAX_RANDOM_VELOCITY = 5;
//
//	public static void main(String args[]) {
//		PApplet.main(new String[] { "--present",
//				"fr.afcepf.atod12.processing.matiereVsAntimatiere.MatiereVsAntimatiere" });
//	} 
//
//	// Generateur de balle avec copie de tableazu
//	public Ball generateRandomBall() {
//		int type = (int)random(2.5f);
//		return new Ball(random(1500), random(900), random(MAX_RANDOM_SIZE), type);
//	}
//	
//	public PVector generateRandomVel() {
//		return new PVector((float)random(MAX_RANDOM_VELOCITY), (float)random(MAX_RANDOM_VELOCITY));
//	}
//	
//	public void setup() {
////		myServer = new Server(this, 5204);
//		PopulateWorld(8);
//		size(1600, 1000);
//		smooth();
//		noStroke();
//	}
//
//	private void PopulateWorld(int nbBalls) {
//		balls = new Ball[nbBalls];
//		vels = new PVector[nbBalls];
//		for(int i = 0; i < nbBalls; i++) {
//			balls[i] = generateRandomBall();
//			vels[i] = generateRandomVel();
//		}
//	}
//
//	public void draw() {
//		background(500);
//		fill(204);
//		for (int i = 0; i < balls.length; i++) {
//			if (balls[i] != null) {
//				balls[i].x += vels[i].x;
//				balls[i].y += vels[i].y;
//				ellipse(balls[i].x, balls[i].y, balls[i].r * 2, balls[i].r * 2);
//				fill(balls[i].c);
//				// Check les collisions avec les murs
//				checkBoundaryCollision(balls[i], vels[i]);
//			}
//		}
//		if (balls != null) {
//			// Check les collisions entre les balles
//			checkObjectCollision(balls, vels);
//		}
//		// TODO : Ajouter le serveur 
//		// myServer.write(balls[0].toString());
//	}
//
//	public void checkObjectCollision(Ball[] b, PVector[] v) {
//
//		// Boucle qui compare les boules 2 � 2 :
//		for (int i = 0; i < balls.length - 1; i++) {
//			if (b[i] == null || b[i + 1] == null)
//				continue;
//			// get distances between the balls components
//			PVector bVect = new PVector();
//			bVect.x = b[i].x - b[i + 1].x;
//			bVect.y = b[i].y - b[i + 1].y;
//
//			// calculate magnitude of the vector separating the balls
//			float bVectMag = sqrt(bVect.x * bVect.x + bVect.y * bVect.y);
//			if (bVectMag < b[i].r + b[i + 1].r) {
//				// If type particle is different, total annihilation :
//				if (b[i + 1].t != b[i].t) {
//					b[i] = null;
//					b[i + 1] = null;
//					continue;
//				}
//
//				// get angle of bVect
//				float theta = atan2(bVect.y, bVect.x);
//				// precalculate trig values
//				float sine = sin(theta);
//				float cosine = cos(theta);
//
//				/*
//				 * bTemp will hold rotated ball positions. You just need to
//				 * worry about bTemp[1] position
//				 */
//				Ball[] bTemp = { new Ball(balls[i].t), new Ball(balls[i+1].t) };
//
//				/*
//				 * b[1]'s position is relative to b[0]'s so you can use the
//				 * vector between them (bVect) as the reference point in the
//				 * rotation expressions. bTemp[0].x and bTemp[0].y will
//				 * initialize automatically to 0.0, which is what you want since
//				 * b[1] will rotate around b[0]
//				 */
//				bTemp[1].x = cosine * bVect.x + sine * bVect.y;
//				bTemp[1].y = cosine * bVect.y - sine * bVect.x;
//
//				// rotate Temporary velocities
//				PVector[] vTemp = { new PVector(), new PVector() };
//				vTemp[0].x = cosine * v[0].x + sine * v[0].y;
//				vTemp[0].y = cosine * v[0].y - sine * v[0].x;
//				vTemp[1].x = cosine * v[1].x + sine * v[1].y;
//				vTemp[1].y = cosine * v[1].y - sine * v[1].x;
//
//				/*
//				 * Now that velocities are rotated, you can use 1D conservation
//				 * of momentum equations to calculate the final velocity along
//				 * the x-axis.
//				 */
//				PVector[] vFinal = { new PVector(), new PVector() };
//				// final rotated velocity for b[0]
//				vFinal[0].x = ((b[i].m - b[i + 1].m) * vTemp[0].x + 2
//						* b[i + 1].m * vTemp[1].x)
//						/ (b[i].m + b[i + 1].m);
//				vFinal[0].y = vTemp[0].y;
//				// final rotated velocity for b[0]
//				vFinal[1].x = ((b[i + 1].m - b[i].m) * vTemp[1].x + 2 * b[i].m
//						* vTemp[0].x)
//						/ (b[i].m + b[i + 1].m);
//				vFinal[1].y = vTemp[1].y;
//
//				// hack to avoid clumping
//				bTemp[0].x += vFinal[0].x;
//				bTemp[1].x += vFinal[1].x;
//
//				/*
//				 * Rotate ball positions and velocities back Reverse signs in
//				 * trig expressions to rotate in the opposite direction
//				 */
//				// rotate balls
//				Ball[] bFinal = { new Ball(balls[i].t), new Ball(balls[i+1].t) };
//				bFinal[0].x = cosine * bTemp[0].x - sine * bTemp[0].y;
//				bFinal[0].y = cosine * bTemp[0].y + sine * bTemp[0].x;
//				bFinal[1].x = cosine * bTemp[1].x - sine * bTemp[1].y;
//				bFinal[1].y = cosine * bTemp[1].y + sine * bTemp[1].x;
//
//				// update balls to screen position
//				// Correction du code initial qui confondait les references a
//			 	// ajouter
//				b[i + 1].x = b[i + 1].x + bFinal[1].x;
//				b[i + 1].y = b[i + 1].y + bFinal[1].y;
//				b[i].x = b[i].x + bFinal[0].x;
//				b[i].y = b[i].y + bFinal[0].y;
//
//				// update velocities
//				v[i].x = cosine * vFinal[0].x - sine * vFinal[0].y;
//				v[i].y = cosine * vFinal[0].y + sine * vFinal[0].x;
//				v[i + 1].x = cosine * vFinal[1].x - sine * vFinal[1].y;
//				v[i + 1].y = cosine * vFinal[1].y + sine * vFinal[1].x;
//			}
//		}
//	}
//
//	void checkBoundaryCollision(Ball ball, PVector vel) {
//		if (ball.x > width - ball.r) {
//			ball.x = width - ball.r;
//			vel.x *= -1;
//		} else if (ball.x < ball.r) {
//			ball.x = ball.r;
//			vel.x *= -1;
//		} else if (ball.y > height - ball.r) {
//			ball.y = height - ball.r;
//			vel.y *= -1;
//		} else if (ball.y < ball.r) {
//			ball.y = ball.r;
//			vel.y *= -1;
//		}
//	}
//
//}
